home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-15 | 6.7 KB | 245 lines | [TEXT/PJMM] |
- { ircle - Internet Relay Chat client }
- { File: IRCSComm }
- { Copyright © 1992 Olaf Titz (s_titz@ira.uka.de) }
-
- { This program is free software; you can redistribute it and/or modify }
- { it under the terms of the GNU General Public License as published by }
- { the Free Software Foundation; either version 2 of the License, or }
- { (at your option) any later version. }
-
- { This program is distributed in the hope that it will be useful, }
- { but WITHOUT ANY WARRANTY; without even the implied warranty of }
- { MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the }
- { GNU General Public License for more details. }
-
- { You should have received a copy of the GNU General Public License }
- { along with this program; if not, write to the Free Software }
- { Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. }
-
- unit IRCSComm;
- { Handles messages and commands from server }
-
- interface
- uses
- TCPTypes, TCPStuff, TCPConnections, ApplBase, MiscGlue, MsgWindows, IRCGlobals,{}
- IRCAux, IRCPreferences, IRCChannels, CTCP, IRCCommands, IRCNComm,{}
- IRCNotify, IRCIgnore;
-
- procedure ServerCommands (var s: string);
- { Handle command line got from server }
-
- implementation
-
- procedure ServerCommands (var s: string);
- var
- i: integer;
- ign: boolean;
- from, target, comm: string[40];
- fromuser: string[60];
- st: string;
- dd: MWHndl;
- begin
- st := '';
- if s[1] = ':' then begin
- i := pos(' ', s);
- fromuser := copy(s, 2, i - 2);
- delete(s, 1, i);
- end
- else
- fromuser := '';
- NextArg(s, comm);
- i := pos(' ', s);
- if i = 0 then
- target := ''
- else begin
- target := copy(s, 1, i - 1);
- delete(s, 1, i)
- end;
- ign := IsIgnored(fromuser, (comm <> 'NOTICE'));
- i := pos('!', fromuser); { nick!user@host -> nick }
- if i > 0 then begin
- from := copy(fromuser, 1, i - 1);
- delete(fromuser, 1, i)
- end
- else begin
- from := fromuser;
- fromuser := '';
- end;
- if s[1] = ':' then
- delete(s, 1, 1);
-
- if (comm[1] >= '0') and (comm[1] <= '9') then begin
- {the following line will decode an exact-3-digit-number...}
- if not NumericComm(ord(comm[1]) * 100 + ord(comm[2]) * 10 + ord(comm[3]) - 5328, from, target, s) then begin
- flushing := false;
- end
- else
- st := 'NUM';
- end
- { These are the commands sent to the client as defined in the IRCII and 2.7 server sources. }
- { Commands obsoleted by 2.7 are taken out! }
- else if comm = 'NOTICE' then
- if ign then
- st := 'I'
- else begin
- doCTCP(from, target, s, true);
- if s = '' then
- st := 'CTCP'
- else begin
- begin
- if (from = '') or (from = CurrentServer) then
- st := s
- else begin
- if CurrentServer = '' then begin
- CurrentServer := from;
- st := s
- end
- else
- st := concat('-', from, '- ', s);
- end;
- if IsChannel(target) then
- ChannelMsg(target, st)
- else
- ChannelMsg(from, st);
- end
- end
- end
- else if comm = 'PRIVMSG' then
- if ign then
- st := 'I'
- else begin
- doCTCP(from, target, s, false);
- if s = '' then
- st := 'CTCP'
- else begin
- if IsChannel(target) then begin
- st := concat('<', from, '> ', s); { Public message }
- ChannelMsg(target, st);
- end
- else if equalstring(target, currentNick, false, true) then begin
- st := concat('*', from, '* ', s); { Private message }
- ChannelMsg(from, st);
- lastMSG := from;
- end
- else begin
- st := concat('(', from, ')', s); { possibly bogus? }
- Message(s);
- end
- end
- end
- else if comm = 'JOIN' then begin
- if EqualString(from, CurrentNick, false, true) then begin
- currentTarget := s;
- dd := DoJoin(currentTarget);
- st := concat('MODE ', s);
- HandleCommand(st);
- st := 'J';
- end
- else begin
- OneNotify(from, true);
- if fromuser = '' then
- st := concat('*** ', from, ' has joined ', s)
- else
- st := concat('*** ', from, ' [', fromuser, '] has joined ', s);
- lastMSG := from;
- if ShowJOIN then
- ChannelMsg(s, st)
- end
- end
- else if comm = 'PART' then begin
- if from = currentNick then begin
- st := s;
- DoPart(st)
- end
- else begin
- st := concat('*** ', from, ' has left ', s);
- if ShowPART then
- ChannelMsg(s, st);
- end
- end
- else if comm = 'QUIT' then begin { is special in that it has no target par }
- OneNotify(from, false);
- if target <> '' then begin
- if target[1] = ':' then
- delete(target, 1, 1);
- target := concat(target, ' ')
- end;
- st := concat('*** Signoff: ', from, ' (', target, s, ')');
- if ShowQUIT then
- Message(st);
- end
- else if comm = 'WALLOPS' then begin
- st := concat('!', from, '! ', s);
- if ShowWALLOPS then
- LineMsg(st);
- end
- else if comm = 'PING' then begin
- st := concat('PONG ', default^^.userloginname, ' ', s);
- HandleCommand(st);
- st := 'PONG'
- end
- else if comm = 'TOPIC' then begin
- st := concat(from, ' has set the topic on ', target, ' to ', s);
- if showTOPIC then
- ChannelMsg(target, st)
- end
- else if comm = 'PONG' then begin
- st := concat('*** Got PONG from ', from);
- Message(st);
- end
- else if comm = 'INVITE' then begin
- st := concat('*** ', from, ' invites ', target, ' to channel ', s);
- lastInvite := s;
- if ShowINVITE then
- ChannelMsg(s, st)
- end
- else if comm = 'NICK' then begin
- if EqualString(from, CurrentNick, false, true) then begin
- CurrentNick := s;
- SetMainTitle(CurrentNick);
- end;
- OneNotify(from, false);
- OneNotify(s, true);
- st := concat('*** ', from, ' is now known as ', s);
- if ShowNICK then
- Message(st)
- end
- else if comm = 'KILL' then begin
- if pos('.', from) > 0 then begin { server kill }
- st := concat('*** You have been rejected by ', from, ' (', s, ')');
- LineMsg(st);
- end
- else begin { operator kill: display alert box & quit }
- { Incompletely tested; maybe the path gets too long and the reason isn't displayed }
- paramtext(from, s, '', '');
- i := Alert(A_OPKILL, nil);
- QuitRequest := true
- end;
- end
- else if comm = 'MODE' then begin
- st := concat(from, ' changed the mode on ', target, ' to "', s, '"');
- if ShowMODE then
- ChannelMsg(target, st);
- end
- else if comm = 'KICK' then begin
- if EqualString(s, CurrentNick, false, true) then begin
- st := concat('*** You have been kicked from ', target, ' by ', from);
- ChannelMsg(target, st);
- Inactive(target);
- end
- else begin
- st := concat(from, ' kicked ', s, ' from ', target);
- if ShowKICK then
- ChannelMsg(target, st)
- end
- end
- else if (comm = 'ERROR') or (comm = 'ERROR:') then begin {the : form honors buggy servers }
- st := concat('*** (', from, ') ', target, ' ', s)
- end;
- if st = '' then begin { Display unprocessed commands. }
- st := concat('/', comm, '/', from, '/', target, '/', s, '/');
- LineMsg(st);
- end;
- end;
-
- end.